package com.gy.zpchat.util.widget;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.annotation.NonNull;

import com.gy.zpchat.R;


/**
 * Created by zego on 2019/4/16.
 */

public class SelectorDialog extends Dialog implements View.OnClickListener {

    public SelectorOnClick click;

    public SelectorDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);

    }

    Button buttonFile, buttonImage,btnCall;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.selector_dialog_view);
        buttonFile = findViewById(R.id.bt_file);
        buttonFile.setOnClickListener(this);
        buttonImage = findViewById(R.id.bt_image);
        buttonImage.setOnClickListener(this);
        btnCall = findViewById(R.id.bt_call);
        btnCall.setOnClickListener(this);
    }

    private static SelectorDialog customDialog;

    @Override
    public void show() {
        synchronized (this) {
            super.show();
        }
    }

    public void setClick(SelectorOnClick click) {
        this.click = click;
    }

    @Override
    public void cancel() {
        synchronized (this) {
            super.cancel();
            customDialog = null;
        }
    }

    public static SelectorDialog createDialog(Activity activity) {
        if (customDialog == null)

            synchronized (SelectorDialog.class) {
                customDialog = new SelectorDialog(activity, 0);
            }

        return customDialog;
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.bt_file) {
            if (click != null) {
                click.onClickFile();
            }
        } else if (v.getId() == R.id.bt_image) {
            if (click != null) {
                click.onClickImage();
            }
        }else if (v.getId() == R.id.bt_call){
            if (click!=null){
                click.onClickCall();
            }
        }
    }

   public interface SelectorOnClick {
        void onClickFile();
        void onClickImage();
        void onClickCall();
    }
}


